<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pet Training Game</title>

</head>
<html>
<body>
<div id="fb-root"></div>
<div id="applet"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="deployJava.js"></script>
<script>

  var t;
  var success = false;
  var appId = "135474096504656";
  
  var host = window.location.host;
  function S4() {
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
  }
  function guid() {
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
  }
  
  t=setTimeout("bootstrap()",3000);
  FB.init({
    appId  : appId,
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
  
  FB.getLoginStatus(function(response) {
    if (response.session) {
      clearTimeout(t);
      
      var id = response.session.uid;
      if (''+id == 'undefined') {
        launch(guid());
      }
      else {
        FB.api('/me', function(response) {
          var n = response.name.replace(" ",".");
          launch(n + id);
        });
      }
    }
    else {
      var u = "https://www.facebook.com/dialog/oauth?" +
          "client_id=" + appId + "&redirect_uri=http://www.eerbaar.com&response_type=token";
      window.location = u;
    }
  });
  
  function bootstrap() {
    var u = "https://www.facebook.com/dialog/oauth?" +
      "client_id=" + appId + "&redirect_uri=http://www.eerbaar.com&response_type=token";
    window.location = u;
    //launch(guid());
  }
  var applet = '';
  function launch(clientid) {
    if (!success) { 
      var attributes = { 
        code:'eerbaar.v2.client.Applet', 
        width:750, height:550
      };
    
      var u = 'http://' + host + '/';
      var parameters = { 
        jnlp_href: u + 'eerbaar2.jnlp', 
        server: u, 
        userid: clientid,
        client: '@eerbaar.client@'
      } ;
    
      document.write = function(data) {applet += data + ' ';};
      deployJava.runApplet(attributes, parameters, '1.6');
      var x=document.getElementById("applet");
      x.innerHTML = applet;
      success=true;
    }
  }
</script>
</body>
</html>
